package com.yf.course.modules.course.controller;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.yf.ability.live.dto.LiveBuildDTO;
import com.yf.ability.live.service.LiveBuildService;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.course.modules.course.dto.CourseLiveDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* <p>
* 课程信息控制器
* </p>
*
* @author 聪明笨狗
* @since 2020-12-17 11:28
*/
@Api(tags={"课程直播"})
@RestController
@RequestMapping("/api/course/live")
public class CourseLiveController extends BaseController {


    @Autowired
    private LiveBuildService liveBuildService;

    /**
     * 构建直播地址
     * @return
     */
    @ApiOperation(value = "构建直播地址")
    @PostMapping("/gen")
    public ApiRest<CourseLiveDTO> gen() {

        String id = IdWorker.getIdStr();

        // 产生直播
        LiveBuildDTO live = liveBuildService.buildLive(id);
        CourseLiveDTO respDTO = new CourseLiveDTO();
        respDTO.setId(id);
        respDTO.setPushUrl(live.getPushUrl());
        respDTO.setM3u8Url(live.getM3u8Url());
        respDTO.setPullUrl(live.getPullUrl());
        respDTO.setFlvUrl(live.getFlvUrl());

        return super.success(respDTO);
    }

}
